package dao;

import java.sql.*;

public class JDBC {
    private static final String driver;
    private static final String url;
    private static final String user;
    private static final String pwd;
    static {
        driver = "com.mysql.jdbc.Driver";
        url = "jdbc:mysql://localhost/epidemic";
        user = "root";
        pwd = "WJHwenjiahui245";
    }
    public static void loadDriver() throws ClassNotFoundException {
        Class.forName(driver);
    }
    public static Connection getConnection() throws ClassNotFoundException, SQLException {
        loadDriver();
        Connection con= DriverManager.getConnection(url,user,pwd);
        return con;
    }
    public static void release(Statement stmt, Connection con)  {
        if (stmt!=null) {
            try {
                stmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            stmt=null;
        }
        if (con!=null) {
            try {
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            con=null;
        }
    }
    public static void release(ResultSet rs, Statement stmt, Connection con){
        if (stmt!=null) {
            try {
                stmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            stmt=null;
        }
        if (con!=null) {
            try {
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            con=null;
        }if (rs!=null) {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            rs=null;
        }
    }
}
